package com.tedu.weibo.controller;

import com.tedu.weibo.mapper.CommentMapper;
import com.tedu.weibo.pojo.dto.CommentDTO;
import com.tedu.weibo.pojo.entity.Comment;
import com.tedu.weibo.pojo.entity.User;
import com.tedu.weibo.pojo.vo.CommentVO;
import com.tedu.weibo.result.JsonResult;
import com.tedu.weibo.result.Status;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/comment")
@Api(tags = "评论模块")
public class CommentController {
    @Autowired
    private CommentMapper commentMapper;
    @ApiOperation(value = "发表评论")
    @PostMapping ("/insert")
    public JsonResult insert(@RequestBody @Validated CommentDTO commentDTO, @ApiIgnore HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null){
            return new JsonResult(Status.NOT_LOGIN);
        }
        Comment comment = new Comment();
        BeanUtils .copyProperties(commentDTO,comment);
        comment.setUserId(user.getId());
        comment.setCreated(new Date());
        commentMapper.insert(comment);
        return JsonResult.success();
    }
    @ApiOperation(value = "根据微博id查询评论")
    @GetMapping("/selectByWeiboId")
    @ApiImplicitParam(name = "id",value = "微博id",required = true,example = "10",dataType = "int")
    public JsonResult selectByWeiboId(Integer id){
        return JsonResult.success(commentMapper.selectByWeiboId(id)) ;
    }
    @ApiOperation(value = "查看指定微博下指定用户的评论")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "weiboId",value = "微博id",required = true,example = "10",dataType = "int"),
        @ApiImplicitParam(name = "userId",value = "用户id",required = true,example = "10",dataType = "int")
    })
    public JsonResult findByWeiboIdAndUserId(Integer weiboId,Integer userId){
        return null;
    }
}
